const mysql = require('mysql');
const config = {
  host: 'localhost',
  user: 'root',
  password: 'root123',
  database: 'book',
};
const DB = mysql.createConnection(config);
DB.connect(err => {
  if (err) {
    console.log(err);
  } else {
    console.log('数据库连接成功');
  }
});
function query(sql, data) {
  return new Promise((resolve, reject) => {
    DB.query(sql, data, (err, data) => {
      if (err) {
        reject(err);
      } else {
        resolve(data);
      }
    });
  });
}

module.exports = {
  query,
};
